package messages;

import util.Utils;

public class ParListElement {

	public static final int	PAR_LIST_ELEMENT_SIZE	= 26;	// bytes

	// MsgID Fields
	private short			sourceID;
	private short			channelID;
	private short			msgType;
	private byte			sourceNo;
	private byte			channelNo;
	// private byte NULL = 0;
	private byte			layer;

	// AsciiID Fields
	private short[]			chars;							// size = 8 chars

	public ParListElement( short _sourceID , short _channelID , short _msgType , byte _sourceNo ,
			byte _channelNo , byte _layer , short[] _chars ) {
		this.sourceID = _sourceID;
		this.channelID = _channelID;
		this.msgType = _msgType;
		this.sourceNo = _sourceNo;
		this.channelNo = _channelNo;
		this.layer = _layer;
		this.chars = _chars;
	}

	public short getSourceID( ) {
		return sourceID;
	}

	public void setSourceID( short sourceID ) {
		this.sourceID = sourceID;
	}

	public short getChannelID( ) {
		return channelID;
	}

	public void setChannelID( short channelID ) {
		this.channelID = channelID;
	}

	public short getMsgType( ) {
		return msgType;
	}

	public void setMsgType( short msgType ) {
		this.msgType = msgType;
	}

	public byte getSourceNo( ) {
		return sourceNo;
	}

	public void setSourceNo( byte sourceNo ) {
		this.sourceNo = sourceNo;
	}

	public byte getChannelNo( ) {
		return channelNo;
	}

	public void setChannelNo( byte channelNo ) {
		this.channelNo = channelNo;
	}

	public byte getLayer( ) {
		return layer;
	}

	public void setLayer( byte layer ) {
		this.layer = layer;
	}

	public short[] getChars( ) {
		return chars;
	}

	public void setChars( short[] chars ) {
		this.chars = chars;
	}

	public byte[] assembleMsgID( ) {
		byte[] msgID = new byte[Utils.MSG_ID_LENGTH];
		byte[] tmp;

		tmp = Utils.shortToBytes( sourceID );
		msgID[0] = tmp[1];
		msgID[1] = tmp[0];

		tmp = Utils.shortToBytes( channelID );
		msgID[2] = tmp[1];
		msgID[3] = tmp[0];

		tmp = Utils.shortToBytes( msgType );
		msgID[4] = tmp[1];
		msgID[5] = tmp[0];

		msgID[6] = sourceNo;
		msgID[7] = channelNo;
		msgID[8] = layer;
		msgID[9] = 0; // NULL

		return msgID;
	}

	@Override
	public String toString( ) {
		return "{MsgID=<SourceID=" + ( sourceID & 0x0000ffff ) + "><ChannelID="
				+ ( channelID & 0x0000ffff ) + "><MsgType=" + ( msgType & 0x0000ffff )
				+ "><SourceNo=" + ( sourceNo & 0x000000ff ) + ".ChannelNo="
				+ ( channelNo & 0x000000ff ) + "><Layer=" + ( layer & 0x000000ff ) + ".NULL>}";
	}
}
